import http from "@/utils/http";
import type * as User from "./type";
import type { MenuItem } from "@/apis";
import type { ChangeMobile, MessageItem } from "./type";

/**
 * @desc 获取短信验证码
 */
export const getVerifyCode = (params: { mobile: string }) => {
  return http.get<{ mobile: string }>("/auth/sms/code", params);
};

/**
 * @desc 登录
 * @param data
 */
export const login = (data: User.loginData) => {
  return http.post<User.LoginRes>("/auth/login", data);
};

/**
 * @desc 获取用户信息
 */
export const getUserInfo = () => {
  return http.get<User.UserInfo>("/sass/user/getInfo");
};

/**
 * @desc 获取路由
 */
export const getUserRoutes = () => {
  return http.get<MenuItem[]>("/sass/menu/getRouters");
};

/**
 * @desc 获取菜单树
 */
export const menuTree = () => {
  return http.get<MenuItem[]>("/sass/menu/tree");
};

/**
 * 用户修改密码
 * @param data
 */
export const updatePassword = (data: { password: string; oldPassword: string }) => {
  return http.post("/sass/user/updatePassword", data);
};

/**
 * @desc 首次登录强制修改初始密码
 */
export const changePassword = (data: { password: string }) => {
  return http.post("/sass/user/restPassword", data);
};

/**
 * @desc 密码找回
 */
export const resetPassword = (data: User.ResetPasswordRes) => {
  return http.post("/auth/retrievePassword", data);
};

/**
 * @desc 管理员重置初始密码
 */
export const restDefaultPassword = (userId: string) => {
  return http.put(`/sass/user/restDefaultPassword/${userId}`);
};

/**
 * @desc 退出登录
 * */
export const logout = () => {
  return http.post("/auth/doLogout");
};

/**
 * @desc 新增人员
 */
export const addPersonnel = (data: User.PersonnelInfo, deptId?: string) => {
  return http.post(`/sass/user/add?deptId=${deptId}`, data);
};

/**
 * @desc 编辑人员
 */
export const editPersonnel = (data: User.PersonnelInfo, userId: string | number) => {
  return http.put(`/sass/user/update/${userId}`, data);
};

/**
 * @desc 查看人员详情
 */
export const getPersonnelDetail = (userId: string) => {
  return http.get<User.PersonnelInfo>(`/sass/user/detail/${userId}`);
};

/**
 * @desc 设置人员状态
 */
export const setPersonnelStatus = (status: boolean, userId: string) => {
  return http.put(`/sass/user/update/${status}/${userId}`);
};

/**
 * @desc 搜索负责人
 */
export const searchPersonnel = (data: { name: string }) => {
  return http.get<User.SearchUser[]>("/sass/user/search", data);
};

/**
 * @desc 修改手机号码
 */
export const updateMobile = (data: User.ChangeMobile) => {
  return http.post("/sass/user/bindMobile", data);
};

/**
 * @desc 获取验证码修改手机号
 */
export const getVerifyCodeUpdateMobile = (mobile: string) => {
  return http.get("/auth/sendSms/code", { mobile });
};
/**获取住户小程序码 */
export const getCode = () => {
  return http.get<BlobPart>(
    "/crm/wx_applet/getCrmUnlimitedQRCode",
    {},
    {
      responseType: "blob"
    }
  );
};
/**获取消息中心列表 */
export const getMessageList = (isRead?: boolean) => {
  return http.get<MessageItem[]>("/sass/message/list", { isRead });
};

/**
 * 将消息设为已读
 */
export const setMessageRead = (messageIds: string[]) => {
  return http.put("/sass/message/read", messageIds);
};

// 省市区
export function getArea() {
  return http.get("/dbo/region/tree");
}

//图片上传，存到业务端
export const imgsUploadFac = (data: any) => {
  http.post("/sass/file/upload", data);
};

/**
 * 查询工厂端租户信息
 */
export const getFactoryInfo = (props: any) => {
  return http.get<MessageItem[]>(`/mall/tenant/factory/info/getFactoryInfo/${props.factoryId}`);
};

/**
 * 保存租户信息
 */
export const saveFactoryInfo = (data: User.ChangeMobile) => {
  return http.post("/mall/tenant/factory/info/saveFactoryInfo", data);
};

/**
 * 获取logo
 */
export const designerLogo = () => {
  return http.post("/mall/shopWebSetting/get");
};

/**
 * 保存自有工厂收款计划
 */
export const savePlan = (data: any) => {
  return http.post("/mall/tenant/merchant/tenant/plan", data);
};

/**
 * 查询组织架构
 */
export const getOrgTree = (params: any) => {
  return http.get("/process/org/tree", params);
};

/**
 * 查询系统角色
 * @returns {*}
 */
export const getRole = () => {
  return http.get("/process/org/user/sign");
};

/**
 * 搜索人员
 * @param { object } params
 * @param { string } params.userName -用户名
 */
export const getUserByName = (params: { userName: string }) => {
  return http.get("/process/org/tree/user/search", params);
};

/**
 * 获取代理商h5商城地址
 * @returns {*}
 */
export const getH5Url = () => {
  return http.get("/mall/agent/systemConfig/getH5Url");
};
/**
 * 获取加盟商设置的icon logon title
 * @returns {*}
 */
export const getLogoIcon = (agentTenantId: any) => {
  return http.get(`/mall/agent/systemConfig/getDetail/${agentTenantId}`);
};
